<template>
	<view class="container">
		<view class="zx-detail-con">
			<text class="zx-detail-title">{{detailList.title}}</text>
			<view class="zx-detail-date">
				<view class="">{{detailList.createtime}}</view>
				<view class="">{{detailList.view_num}}</view>
				<view>浏览</view>
			</view>
		</view>
		<view class="zx-detail-Text" v-html="content">
			
		</view>
		<view class="zx-detail-btn">
			<view class="zx-detail-btnNav" @click="collbtn(detailList.is_collect,detailList.id)" :class="[detailList.is_collect == 0?'':'zx-detail-btnNavShow']">
				<view class="zx-detail-btnNavIcon">
					<image :src="detailList.is_collect == 0?'../../static/ic_coll1.png':'../../static/ic_coll2.png'" mode=""></image>
				</view>
				<text class="zx-detail-btnText">{{detailList.is_collect == 0?'收藏':'已收藏'}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '../../App.vue';
	export default{
		data(){
			return{
				detailList:[],
				msgId:'',
				content:''
			}
		},
		onLoad(options) {
			this.msgId = options.id
			this.getdetailList()
		},
		onShow() {
			
		},
		methods: {
			getdetailList(){					//资讯列表
				let that = this,
					data = {
					article_id:that.msgId
				}
				app.post('api/article/info',data).then(res=>{
					if(res.code == 1 && res.data != ''){
						that.detailList = res.data
						that.content = res.data.content.replace(/\<img/g, '<img style="max-width:100%!important;height:auto;display:block;margin:10px 0;"')
					}
				})
			},
			collbtn(status,id){						//收藏
				let that = this,
				data = {
					article_id:id
				}
				app.post('api/article/collect',data).then(res=>{
					if(res.code == 1){
						that.getdetailList()
					}
					if(res.code == 401){
						uni.showToast({
							title:res.msg,
							icon:'none',
							mark:true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title:err.msg,
						icon:'none',
						mark:true
					})
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/zixundetail.css");
</style>
